package com.fyzk.activity.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.fyzk.adapter.AttentionGodAdapter;
import com.fyzk.base.BaseFragment;
import com.fyzk.view.widget.CustomLoadMoreView;
import com.fyzk.view.widget.DividerItemDecoration;
import com.tyjc.lottery.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * 关注大神
 */

@ContentView(R.layout.fragment_documentary)
public class AttentionGodFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, BaseQuickAdapter.RequestLoadMoreListener {
    @ViewInject(R.id.rv_race)
    RecyclerView mRvRace;
    @ViewInject(R.id.refresh_race)
    SwipeRefreshLayout mRefreshRace;
    private int mType;

    private AttentionGodAdapter mAdapter;
    private LinearLayoutManager mManager;

    public static AttentionGodFragment newInstance(int type) {

        Bundle args = new Bundle();
        args.putInt("type", type);
        AttentionGodFragment fragment = new AttentionGodFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (null != getArguments()) {
            mType = getArguments().getInt("type");
        }
        return x.view().inject(this, inflater, container);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initViews();
    }

    /**
     * 初始化数据
     */
    private void initViews() {
        mAdapter = new AttentionGodAdapter();
        mManager = new LinearLayoutManager(getContext());
        mRefreshRace.setOnRefreshListener(this);
        mRefreshRace.setColorSchemeColors(Color.RED);
        mRvRace.setLayoutManager(mManager);
        mRvRace.setAdapter(mAdapter);
        DividerItemDecoration decoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        decoration.setDrawable(getContext().getDrawable(R.drawable.item_divide_f4f5f6));
        mRvRace.addItemDecoration(decoration);
        mAdapter.setLoadMoreView(new CustomLoadMoreView());
        mAdapter.setOnLoadMoreListener(this, mRvRace);
        mAdapter.loadMoreEnd(false);
        mAdapter.setPreLoadNumber(3);
    }

    /**
     * 下拉刷新
     */
    @Override
    public void onRefresh() {

    }

    /**
     * 上拉加载下一页
     */
    @Override
    public void onLoadMoreRequested() {

    }
}
